package com.qqtop10.manager.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.qqtop10.manager.dao.BrandMapper;
import com.qqtop10.manager.model.Brand;
import com.qqtop10.manager.model.PagingArgs;
import com.qqtop10.manager.service.BrandService;

@Service("brandService")
public class BrandServiceImpl extends BaseService implements BrandService {
	@Autowired
	private BrandMapper brandMapper;

	@Override
	public List<Brand> all(Brand input, PagingArgs pagingArgs) {
		return brandMapper.all(asMap(input, pagingArgs));
	}

	@Override
	public int count(Brand input) {
		return brandMapper.count(input);
	}

	@Override
	public Brand get(Brand input) {
		return brandMapper.get(input);
	}

	@Override
	public boolean add(Brand input) {
		Brand canInsertInput = new Brand();
		canInsertInput.setName(input.getName());
		canInsertInput = get(canInsertInput);
		if (canInsertInput != null && canInsertInput.getName() != null
				&& canInsertInput.getName().equals(input.getName())) {
			throw new RuntimeException("此品牌名已经存在。");
		}
		return brandMapper.add(input) != 0;
	}

	@Override
	public boolean delete(Brand input) {
		return brandMapper.delete(input) != 0;
	}

	@Override
	public boolean update(Brand input) {
		return brandMapper.update(input) != 0;
	}

	@Override
	public boolean recommend(Brand input) {
		return brandMapper.recommend(input) != 0;
	}

	@Override
	public int updateRecommend(Brand input){
		return brandMapper.update(input);
	}
}
